package com.bupt.server.entity;


import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.bupt.server.obj.PublicData;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.*;

@Data
@TableName("room")
@AllArgsConstructor
@NoArgsConstructor
public class Room {
    @TableField(value = "room_id")
    private int room_id;

    @TableField(value = "room_type")
    private String room_type;

    @TableField(value = "customer_id")
    private String customer_id;

    @TableField(value = "password")
    private String password;

    @TableField(value = "current_temperature")
    private float current_temperature;

    @TableField(value = "target_temperature")
    private float target_temperature;

    @TableField(value = "speed")
    private String speed;

    @TableField(value = "ac_status")
    private String ac_status;

    // 是否有顾客正在住
    @TableField(value = "status")
    private boolean status;

    @TableField(value = "total_air_cost")
    private float total_air_cost;

    @TableField(value = "total_cost")
    private float total_cost;

    public float init_temperature;

    private Map<String, List<Integer>> recordRaw = new HashMap<>();

    public void initRecordRaw() {
        recordRaw.put("high", new ArrayList<>());
        recordRaw.put("medium", new ArrayList<>());
        recordRaw.put("low", new ArrayList<>());
    }

    public void addRecordRaw(String acSpeed, Integer curTime) {
        recordRaw.get(acSpeed).add(curTime);
    }

        public void makeDetailedRecord() {
            for (String speed : recordRaw.keySet()) {
                List<Integer> tempServeRecord = recordRaw.get(speed);
                Collections.sort(tempServeRecord);
                for (int i = 0; i < tempServeRecord.size(); ) {
                    for (int j = i; j < tempServeRecord.size(); ) {
                        if (j == tempServeRecord.size() - 1) {
                            Record r = new Record(
                                    room_id,
                                    tempServeRecord.get(i).toString(),
                                    ""+(tempServeRecord.get(j) + 1),
                                    speed,
                                    tempServeRecord.get(j) - tempServeRecord.get(i) + 1
                            );
                            recordList.add(r);
                            i = j + 1;
                            break;
                        }
                        Integer cur = tempServeRecord.get(j);
                        Integer next = tempServeRecord.get(j + 1);
                        if (cur + 1 == next) {
                            j++;
                        } else {
                            Record r = new Record(
                                    room_id,
                                    tempServeRecord.get(i).toString(),
                                    ""+(tempServeRecord.get(j) + 1),
                                    speed,
                                    tempServeRecord.get(j) - tempServeRecord.get(i) + 1
                            );
                            recordList.add(r);
                            i = j + 1;
                            break;
                        }
                    }
                }

            }
        }

    public List<Record> recordList = new ArrayList<>();
    public int serverTimer = -1;
    public int waitingTimer = -1;
    public String mode = "heat";
    public int start_time = -1;
    public int end_time = -1;
    public int request_time = -1;
    public int record_row = 1;

    public void PrintInfo(){
        System.out.println("room_id: " + room_id);
        System.out.println("current_temperature: " + current_temperature);
        System.out.println("target_temperature: " + target_temperature);
        System.out.println("speed: " + speed);
        System.out.println("total_air_cost: " + total_air_cost);
        System.out.println("ac_status: " + ac_status);
        System.out.println("total_cost: " + total_cost);
    }

    public void PrintZhangDan(){
        System.out.println("room_id: " + room_id);
        System.out.println("enter_room_time: " + start_time);
        System.out.println("quit_room_time: " + end_time);
        System.out.println("total_cost: " + total_cost+total_air_cost);

    }



}
